var app = new Vue({
    el: ".box",
    data: {
        form: { beians: '', head: 1003, token: '', name: '', title: '', logo: '', url: '', Keywords: '', description: '', beian: '', flg: true, beizhu: '' },
    },
    methods: {
        saves() {
            save_info();
        }
    }
});


get_info();
function get_info() {
    var loading = app.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
    axios({
        method: "POST",//类型
        baseURL: '../../api/system.php',//地址
        data: 'data=' + JSON.stringify({ head: 1002, token: (sessionStorage.getItem('token')) })
    }).then(function (res) {
        loading.close();
        if (res.data.code === '200') {
            res.data.data[0].flg = (res.data.data[0].flg - 0) ? true : false;
            res.data.data[0].beizhu = res.data.data[0].beizhu || '更新时间:' + res.data.data[0].timer;
            app.form.id = (res.data.data[0].Id - 0);
            app.form = res.data.data[0];
            console.log(app.form);
        } else if (res.data.code === '500') {
            window.location.href = res.data.href;
        } else {
            app.$message.error(res.data.msg);
        };
    }).catch(function (err) {
        // get_info();
        console.log(err);//失败返回错误信息
    });//获取nav
};//获取系统信息


function save_info() {
    var loading = app.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
    if (app.form.beian.includes('+')) {
        app.form.beian = app.form.beian.replace(/\+/g, "%2B");
    };
    if (app.form.beian.includes("'")) {
        app.form.beian = app.form.beian.replace(/\'/g, "&#x27;");
    };
    if (app.form.beian.includes("&")) {
        app.form.beian = app.form.beian.replace(/\&/g, "%26");
    };
    if (app.form.beian.includes("<")) {
        app.form.beian = app.form.beian.replace(/\</g, "%3C");
    };
    if (app.form.beian.includes(">")) {
        app.form.beian = app.form.beian.replace(/\>/g, "%3E");
    };

    app.form.head = 1003;
    app.form.token = (sessionStorage.getItem('token'));
    app.form.status = app.form.flg ? 1 : 0;
    app.form.beizhu = app.form.beizhu.indexOf('更新时间') != -1 ? '' : app.form.beizhu;
    axios({
        method: "POST",//类型
        baseURL: '../../api/system.php',//地址
        data: 'data=' + JSON.stringify(app.form)
    }).then(function (res) {
        loading.close();
        if (res.data.code === '200') {
            app.$message({
                message: '保存成功~',
                type: 'success'
            });
            setTimeout(function(){
                location.reload();
            },500);
        } else if (res.data.code === '500') {
            window.location.href = res.data.href;
        } else {
            app.$message.error(res.data.msg);
        };
    }).catch(function (err) {
        // save_info();
        console.log(err);//失败返回错误信息
    });
};//保存